﻿//创建时间: 2010-12-15
//创建作者: 李 城
//功能说明: cms外部页面访问基类  广告点击
//最后修改: 2010-12-15
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Web;

using TRPOP.Config;
using TRPOP.Common;

namespace TRPOP.CMS.Web.ExtraBus
{
    /// <summary>
    /// 广告点击
    /// </summary>
    public class Page_Load_AdClick : BasePage
    {
        protected override void OnInit(EventArgs e)
        {
            string strRecommentSubmitUrl = SYSConfig.AdvertisementSkipURL;
            string strDynamicPageName =
                (base.mCurrentUrl.ToLower().Contains(strRecommentSubmitUrl.ToLower().Trim())) ? "AdvertisementSkipURL" : "";
            if (strDynamicPageName == "AdvertisementSkipURL")
                AD_Skip();
            else
                Base_Config.NotFound(base.Page, "CMS后台配置的页面地址和访问的页面不一致(广告)");
            //base.OnInit(e);
        }

        /// <summary>
        /// 广告访问页
        /// </summary>
        public void AD_Skip()
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            int intIndexID = RequestHelper.RequestInt("id");
            AdvscontentManage oAdvscontentManage = new AdvscontentManage();
            AdvscontentInfo oAdvscontentInfo = oAdvscontentManage.GetInfoById(intIndexID);
            if (oAdvscontentInfo == null)
            {
                Response.End();
                return;
            }
            AdvshitInfo oAdvshitInfo = new AdvshitInfo();
            oAdvshitInfo.AddTime = DateTime.Now;
            oAdvshitInfo.AddUserId = 0;
            oAdvshitInfo.AdID = oAdvscontentInfo.AdID;
            oAdvshitInfo.ip = RequestHelper.GetIP();
            if (new AdvshitManage().Save(oAdvshitInfo) == EnumSubmitResult.Success)
            {
                oAdvscontentInfo.Hits = oAdvscontentInfo.Hits + 1;
                oAdvscontentManage.Save(oAdvscontentInfo);
            }
            Response.Redirect(oAdvscontentInfo.Redirect);
        }
    }
}
